using KinonekoSoftware.Foundation.UI.Commands;

namespace KinonekoSoftware.Foundation.UI.ViewModels
{
    partial class ViewModelBase
    {
        
        //-------------------------------------------------------------
        //
        //          Commands
        //
        //-------------------------------------------------------------

        #region Commands

        protected ICommandEX CreateCommand(Action handler, string name = "")
        {
            var cmd = new ActionCommand(handler);

            if (!string.IsNullOrEmpty(name))
            {
                _commands.Add(cmd);
                _commandDictionary.Add(name, cmd);
            }

            return cmd;
        }

        protected ICommandEX CreateCommand(Action handler, Func<bool> canExecuteHandler, string name = "")
        {
            var cmd = new ActionCommand(handler, canExecuteHandler);

            if (!string.IsNullOrEmpty(name))
            {
                _commands.Add(cmd);
                _commandDictionary.Add(name, cmd);
            }

            return cmd;
        }

        protected ICommandEX CreateCommand<T>(Action<T> handler, string name = "")
        {
            var cmd = new FuncCommand<T>(handler);

            if (!string.IsNullOrEmpty(name))
            {
                _commands.Add(cmd);
                _commandDictionary.Add(name, cmd);
            }

            return cmd;
        }

        protected ICommandEX CreateCommand<T>(Action<T> handler, Predicate<T> canExecuteHandler, string name = "")
        {
            var cmd = new FuncCommand<T>(handler, canExecuteHandler);

            if (!string.IsNullOrEmpty(name))
            {
                _commands.Add(cmd);
                _commandDictionary.Add(name, cmd);
            }

            return cmd;
        }

        #endregion
    }
}